MSGRCV

Section: System Calls (2)
Index Return to Main Contents

BSD mandoc
NetBSD  

NAME

msgrcv - receive a message from a message queue  

SYNOPSIS

Fd #include <sys/types.h> Fd #include <sys/ipc.h> Fd #include <sys/msg.h> Ft int Fn msgrcv int msqid void *msgp size_t msgsz long msgtyp int msgflg  

DESCRIPTION

The Fn msgrcv function receives a message from the message queue specified in Fa msqid , and places it into the structure pointed to by Fa msgp . This structure should consist of the following members:
    long mtype;    /* message type */
    char mtext[1]; /* body of message */

mtype is an integer greater than 0 that can be used for selecting messages, mtext is an array of bytes, with a size up to that of the system limit (MSGMAX).

The value of Fa msgtyp has one of the following meanings:

Fa msgsz specifies the maximum length of the requested message. If the received message has a length greater than Fa msgsz it will be silently truncated if the MSG_NOERROR flag is set in Fa msgflg , otherwise an error will be returned.

If no matching message is present on the message queue specified by Fa msqid , the behaviour of Fn msgrcv depends on whether the IPC_NOWAIT flag is set in Fa msgflg or not. If IPC_NOWAIT is set, Fn msgrcv will immediately return a value of -1, and set errno to EAGAIN. If IPC_NOWAIT is not set, the calling process will be blocked until:

If a message is successfully received, the data structure associated with Fa msqid is updated as follows: